package com.idconfirmsystem.remote;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.kymjs.kjframe.KJHttp;
import org.kymjs.kjframe.http.HttpCallBack;
import org.kymjs.kjframe.http.HttpParams;
import org.xmlpull.v1.XmlPullParserException;

import android.util.Log;

import com.idconfirmsystem.model.Bag;
import com.idconfirmsystem.model.MoneyTask;
import com.idconfirmsystem.model.SubTask;
import com.idconfirmsystem.model.Task;
import com.idconfirmsystem.model.User;

public class TaskApi {
	/**
	 * 获取用户的任务 应用场景：（1）守押员获取当天列表 2015-8-11
	 * 
	 * @param userCode
	 *            当前用户的ID
	 * @param taskType
	 *            任务类型：A早送 B晚接 C中调
	 * @param userType
	 *            用户类型：SY守押 KY客户
	 * @return
	 */
	public List<Task> getTaskByUserCode(String userCode, String taskType, String userType) {
		KJHttp kjHttp = new KJHttp();
		HttpParams userParams = new HttpParams();
		userParams.put("taskType", taskType);
		userParams.put("type", userType);
		userParams.put("clerkNo", userCode);
		String url = "http://103.27.4.51:8080/syws/services/TaskService/getTaskList";
		kjHttp.get(url, userParams, new HttpCallBack() {

			@Override
			public void onFailure(int errorNo, String strMsg) {
				// TODO Auto-generated method stub
				super.onFailure(errorNo, strMsg);
			}

			@Override
			public void onSuccess(Map<String, String> headers, byte[] t) {
				// TODO Auto-generated method stub
				super.onSuccess(headers, t);
			}

		});
		return null;
	}

	/**
	 * 获取用户的任务(应用场景：守押员获取当天列表)
	 * 
	 * @param userCode
	 *            当前用户的ID
	 * @param taskType
	 *            任务类型：A早送 B晚接 C中调
	 * @param userType
	 *            用户类型：SY守押 KY客户
	 * @return String
	 */
	public String getTaskSoap(String userCode, String taskType, String userType, String depDate) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getTaskList";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/TaskService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("taskType", taskType);
		soapObject.addProperty("type", userType);
		soapObject.addProperty("clerkNo", userCode);
		soapObject.addProperty("depDate", depDate);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.e("soap", result);
		return result;
	}

	public String getTaskBranchList(String taskId) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getTaskBranchList";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/TaskService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("taskId", taskId);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchList", result);
		return result;
	}

	public String getTaskBranchBagList(String taskBranchId) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getTaskBranchBagList";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/TaskService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("taskId", taskBranchId);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String addTaskBags(String taskBranchId, String bagsNumber, String bagSealNo, String emptyBags,
			String arrivalTime, String userId) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "addTaskBags";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/TaskService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("taskId", taskBranchId);
		soapObject.addProperty("taskId", bagsNumber);
		soapObject.addProperty("taskId", bagSealNo);
		soapObject.addProperty("taskId", emptyBags);
		soapObject.addProperty("taskId", arrivalTime);
		soapObject.addProperty("taskId", userId);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String addTaskBranch(String branchNumber, String forecastTime, String bagsNumber, String bagSealNo,
			String remark, String parentId, String parentTaskId, String branchType, String userId) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "addTaskBranch";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/TaskService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("taskId", branchNumber);
		soapObject.addProperty("taskId", forecastTime);
		soapObject.addProperty("taskId", bagsNumber);
		soapObject.addProperty("taskId", bagSealNo);
		soapObject.addProperty("taskId", remark);
		soapObject.addProperty("taskId", parentId);
		soapObject.addProperty("taskId", parentTaskId);
		soapObject.addProperty("taskId", branchType);
		soapObject.addProperty("taskId", userId);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String getBankPhotoInfo(String clerkId, String pwd) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getBankPhotoInfo";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/BankService.BankServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/BankService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("clerkId", clerkId);
		soapObject.addProperty("pwd", pwd);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String getSystemPhotoInfo(String sysuserId, String pwd) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getSystemPhotoInfo";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/BankService.BankServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/BankService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("sysuserId", sysuserId);
		soapObject.addProperty("pwd", pwd);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String updateVerifyInfo(String id, String clerkId) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "updateVerifyInfo";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/BankService.BankServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/BankService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("id", id);
		soapObject.addProperty("clerkId", clerkId);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	public String getNoticeList(String date, String type) {
		// 命名空间
		String nameSpace = "zyznkj";// http://service.task.mobile.zyzn.com
									// zyznkj
		// 调用方法的名称
		String methodName = "getNoticeList";
		// EndPoint:http://103.27.4.51:8080/syws/services/TaskService.TaskServiceHttpSoap12Endpoint/
		String endPoint = "http://103.27.4.51:8080/syws/services/NoticeService.NoticeServiceHttpSoap11Endpoint/";
		// SOAP Action
		String soapAction = "http://103.27.4.51:8080/syws/services/NoticeService/";
		// 指定WebService的命名空间和调用方法
		SoapObject soapObject = new SoapObject(nameSpace, methodName);
		// 设置需要调用WebService接口的参数
		soapObject.addProperty("date", date);
		soapObject.addProperty("type", type);
		// 生成调用WebService方法调用的soap信息，并且指定Soap版本
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER10);
		envelope.bodyOut = soapObject;
		// 是否调用DotNet开发的WebService
		envelope.dotNet = true;
		envelope.setOutputSoapObject(soapObject);
		HttpTransportSE transport = new HttpTransportSE(endPoint);
		try {
			transport.call(soapAction, envelope);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (XmlPullParserException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 获取返回的数据
		SoapObject object = (SoapObject) envelope.bodyIn;
		// 获取返回的结果
		String result = object.getProperty(0).toString();
		// Log.i("getTaskBranchBagList", result);
		return result;
	}

	/**
	 * 获取早送任务下的送往支行的任务 应用场景：（1）守押员获取任务下的【支行任务】； 2015-8-11
	 * 
	 * @param taskCode
	 * @return
	 */
	public List<SubTask> getSubTaskByTaskCode(String taskCode) {
		return null;
	}

	/**
	 * 获取支行的任务。 应用场景： （1）分行管理员查看本辖区内所有的【支行任务】 （2）支行管理员查看本支行的所有【支行任务】；
	 * （3）支行的银行交接员查看自己的【支行任务】
	 * 
	 * @param customerCode
	 *            客户id
	 * @param taskType
	 *            任务类型：1-早送，2-晚接，3-中调
	 * @return
	 */
	public List<SubTask> getSubTaskByCustomerCode(String customerCode, int taskType) {
		return null;
	}

	/**
	 * 获取支行的任务 2015-8-12
	 * 
	 * @param userCode
	 *            用户id
	 * @param taskType
	 *            任务类型：1-早送，2-晚接，3-中调
	 * @return
	 */
	public List<SubTask> getSubTaskByUserCode(String userCode, int taskType) {
		return null;
	}

	/**
	 * 根据taskCode获取task明细
	 * 
	 * @param taskCode
	 * @return
	 */
	public Task getTaskByTaskCode(String taskCode) {
		return null;
	}

	/**
	 * 身份确认
	 * 
	 * @param taskCode
	 *            任务id
	 * @param userCode
	 *            对方的id【跟设备主人交接的人】
	 * @param pw
	 *            对方的密码
	 * @return 确认成功，返回确认用户的信息；确认失败，返回空值
	 */
	public User check(String taskCode, String userCode, String pw) {
		return null;
	}

	/**
	 * 添加接回的款箱（包） 应用场景：支行银行管理员，针对【支行任务】进行添加箱包操作 2015-8-11
	 * 
	 * @param bag
	 *            款箱（包）
	 * @return 是否添加成功
	 */
	public boolean addBag(Bag bag) {
		return false;
	}

	/**
	 * 如果添加错包了，可以执行删除操作【需求未说明】 2015-8-11
	 * 
	 * @param bag
	 * @return
	 */
	public boolean delBag(Bag bag) {
		return true;
	}

	/**
	 * 增加送款（收款）任务 2015-8-12
	 * 
	 * @param task
	 *            任务
	 * @return 是否添加成功
	 */
	public boolean addMoneyTask(MoneyTask task) {
		return true;
	}

	/**
	 * 删除送款（收款）任务 2015-8-12
	 * 
	 * @param task
	 *            任务
	 * @return 是否删除成功
	 */
	public boolean delMoneyTask(MoneyTask task) {
		return true;
	}
}
